import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

    class Student
    {
        private int id;
        private double Score_PE;
        private double Score_English;
        private  String Name;
        private double Score_Math;
        private double Score_Chinese;
        private double Score_Total;
        public Student(int id,String Name,double score_Math,double score_Chinese,double Score_English,double Score_PE,double score_Total )
        {
            this.id=id;
            this.Name=Name;
            this.Score_Math=score_Math;
            this.Score_Chinese=score_Chinese;
            this.Score_English=Score_English;
            this.Score_PE=Score_PE;
            this.Score_Total=score_Total;
        }

        public void setid(int id) {this.id=id;}
        public void setName(String Name)
        {
            this.Name=Name;
        }
        public void setScore_Math(double Score_Math)
        {
            this.Score_Math=Score_Math;
        }
        public void setScore_Chinese(double Score_Chinese)
        {
            this.Score_Chinese=Score_Chinese;
        }
        public void setScore_English(double Score_English)
        {
            this.Score_English=Score_English;
        }
        public void setScore_PE(double Score_PE)
        {
            this.Score_PE=Score_PE;
        }
        public void setScore_Total(double Score_Total)
        {
            this.Score_Total=Score_Total;
        }
        public Integer getid()
        {
            return id;
        }
        public  String getName()
        {
            return Name;
        }
        public  double getScore_Math()
        {
            return Score_Math;
        }
        public  double getScore_Chinese()
        {
            return Score_Chinese;
        }
        public  double getScore_English()
        {
            return Score_English;
        }
        public  double getScore_PE()
        {
            return Score_PE;
        }
        public double getScore_Total() {
            return Score_Total;
        }
    }
    public class test_12_18 {
        public static void main(String[] args) {
            ArrayList<Student> list=new ArrayList<>();//创建集合
            //创建对象
            Student ST1=new Student(1,"李峋",150,150,150,100,550);
            Student ST2=new Student(2,"朱韵",149,149,149,99,546);
            Student ST3=new Student(3,"任迪",99,99,99,99,396);
            Student ST4=new Student(4,"付一卓",59,59,59,59,236);
            //添加元素
            list.add(ST1);
            list.add(ST2);
            list.add(ST3);
            list.add(ST4);
            int input=0;
            do {
                System.out.println("*************1. 平均成绩         ***************");
                System.out.println("*************2. 降序排列         ***************");
                System.out.println("*************3.每科平均成绩      ***************");
                System.out.println("*************4.按照成绩划分等级  ***************");
                System.out.println("*************5.输入学号查询成绩  ***************");
                System.out.println("*************6.录入学生成绩      ***************");
                System.out.println("*************7.打印学生成绩      ***************");
                System.out.println("*************0.退出             ***************");
                System.out.println("请选择->");
                Scanner in = new Scanner(System.in);
                input = in.nextInt();
                switch (input) {
                    case 1:
                        System.out.println("平均成绩");
                        Average(list);
                        break;
                    case 2:
                        System.out.println("降序排列");
                        Rank(list);
                        break;
                    case 3:
                        System.out.println("每科平均成绩");
                        Average_Score(list);
                        break;
                    case 4:
                        System.out.println("按照成绩划分等级");
                        grade(list);
                        break;
                    case 5:
                        System.out.println("输入学号查询成绩");
                        Find_Student(list);
                        break;
                    case 6:
                        System.out.println("开始录入");
                        Add(list);
                        break;
                    case 7:
                        System.out.println("打印学生信息");
                        Print(list);
                        break;
                    case 0:
                        System.out.println("退出");
                        break;
                    default:
                        System.out.println("选择错误!!!!\n");
                        break;
                }
            } while (input>0);
        }
        public static void Average(ArrayList<Student> list) {//求平均值
            double sum = 0;
            for (int i = 0; i < list.size(); i++) {
                double total=list.get(i).getScore_Total();
                //Student ST = list.get(i);先拿出学生
                //double total = ST.getScore_Total();//在用学生调用出总成绩
                double average=total/5;
                System.out.println(list.get(i).getName()+"平均成绩："+average);
            }
        }
        public static void Rank(ArrayList<Student> list)//求排序
        {

            Collections.sort(list, new Comparator<Student>() {//是集合本身就有的函数
                @Override
                public int compare(Student o1, Student o2) {
                    return (int) (o2.getScore_Total()-(o1.getScore_Total()));
                }
            });
            for(int i=0;i<list.size();i++)
            {
                Student stu=list.get(i);
                System.out.println("姓名：" + stu.getName() + "\t"+"数学：" + stu.getScore_Math() + "语文：" + stu.getScore_Chinese() + "英语：" + stu.getScore_English() + "体育：" + stu.getScore_PE() + "总成绩：" + stu.getScore_Total());

            }
            String Min_Score=list.get(4).getName();
            System.out.println("最低分："+Min_Score );
            String Max_Score=list.get(0).getName();
            System.out.println("最高分："+Max_Score );

        }
        public static void Find_Student(ArrayList<Student> list)//查找学生信息
        {
            Scanner num=new Scanner(System.in);
            System.out.println("请输入要查询学生的学号：");
            int number= num.nextInt();
            int flag=0;
            if(list.size()==0)
            {
                System.out.println("无当前学生信息，请先录入学生信息");
                return;
            }
            for(int i=0;i<list.size();i++) {
                Student stu=list.get(i);
                if (stu.getid() == number) {//获取该学生的学生的学号，和键盘录入的学号作对比
                    flag++;
                    System.out.println("姓名：" + stu.getName() + "数学：" + stu.getScore_Math() + "语文：" + stu.getScore_Chinese() + "英语：" + stu.getScore_English() + "体育：" + stu.getScore_PE() + "总成绩：" + stu.getScore_Total());
                }
            }
            if(flag==0)
            {
                System.out.println("未查询到学生信息");
            }

        }

        public static void Average_Score(ArrayList<Student> list)//求每一个平均值
        {
            double All_Math=0;
            double All_Chinese=0;
            double All_English=0;
            double All_PE=0;
            for(int i=0;i<list.size();i++) {
                Student stu = list.get(i);
                All_Math=All_Math+stu.getScore_Math();
                All_Chinese=All_Chinese+ stu.getScore_Chinese();
                All_English+= stu.getScore_English();
                All_PE+= stu.getScore_PE();
            }
            double Aver_Math=All_Math/5;
            double Aver_Chinese=All_Chinese/5;
            double Aver_English=All_English/5;
            double Aver_PE=All_PE/5;
            System.out.println("数学："+Aver_Math+"语文："+Aver_Chinese+"英语："+Aver_English+"体育："+Aver_PE+"\n");
            double []arr={Aver_Math,Aver_Chinese,Aver_English,Aver_PE};
            double Max_Aver=arr[0];
            double Min_Aver=arr[0];
            for(int i=0;i<arr.length;i++)
            {
                if(Max_Aver<arr[i])
                {
                    Max_Aver=arr[i];
                }
                if(Min_Aver>arr[i])
                {
                    Min_Aver=arr[i];
                }
            }
            System.out.println("最高分："+Max_Aver);
            System.out.println("最低分："+Min_Aver);
        }
        public static void grade(ArrayList<Student> list)//学生的等级划分
        {
            int A = 0;
            int B = 0;
            int C = 0;
            int E = 0;
            for (int i = 0; i < list.size(); i++) {
                Student stu = list.get(i);
                double total = stu.getScore_Total();
                if (total >= 500) {
                    System.out.println(stu.getName() + "\t" + "A");
                    A++;
                }
                if (total < 500 && total >= 400) {
                    System.out.println(stu.getName() + "\t" + "B");
                    B++;
                }
                if (total < 400 && total >= 300) {
                    System.out.println(stu.getName() + "\t" + "C");
                    C++;
                }
                if (total < 300) {
                    System.out.println(stu.getName() + "\t" + "不及格");
                    E++;
                }
            }
            System.out.println("A:" + A);
            System.out.println("B:" + B);
            System.out.println("C:" + C);
            System.out.println("E:" + E);
        }
        public static void Add(ArrayList<Student> list)//添加学生信息
        {
            Scanner sc=new Scanner(System.in);//创建学生对象
            Student ST=new Student(0,"0",0,0,0,0,0);
            System.out.println("请输入学生姓名：");
            String name = sc.next();
            ST.setName(name);
            System.out.println("请输入学号：");
            int id = sc.nextInt();
            ST.setid(id);
            System.out.println("请输入数学成绩：");
            double math = sc.nextDouble();
            ST.setScore_Math(math);
            System.out.println("请输入语文成绩：");
            double chinese = sc.nextDouble();
            ST.setScore_Chinese(chinese);
            System.out.println("请输入英语成绩：");
            double English = sc.nextDouble();
            ST.setScore_English(English);
            System.out.println("请输入体育成绩：");
            double PE = sc.nextDouble();
            ST.setScore_PE(PE);
            double Score_Total =math+chinese+English +PE;
            ST.setScore_Total(Score_Total);
            list.add(ST);
        }
        public static void Print(ArrayList<Student> list)//输出打印
        {
            System.out.println("姓名\t学号 数学     语文    英语    体育    总分");
            for(int i=0;i<list.size();i++){
                Student stu=list.get(i);
                System.out.println(stu.getName() +"\t"+stu.getid()+"\t"+stu.getScore_Math() +"\t"+ stu.getScore_Chinese() +"\t"+ stu.getScore_English() +"\t"+ stu.getScore_PE()+"\t"+stu.getScore_Total() );
            }
        }
    }

